class Dispatcher {
    constructor() {
        this.id = 0
        this.events = []
    }

    send(event, data) {
        if (!event) return
        this.events.filter(v => {
            return v.event === event
        }).forEach(v => {
            v.observer(data)
        })
    }

    on(event, observer) {
        this.events.push({
            id: ++this.id,
            event,
            observer
        })
        return this.id
    }

    off(id) {
        if (!id) return
        this.events = this.events.filter(v => {
            return v.id !== id
        })
    }
}

if (!window._bus) window._bus = new Dispatcher()
